// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

// MUI
import Mui from 'vue-awesome-mui'
import 'vue-awesome-mui/mui/dist/css/mui.css'
Vue.use(Mui)

import VueCookie from 'vue-cookie';
// Tell Vue to use the plugin
Vue.use(VueCookie);

import md5 from './plugins/md5'
Vue.use(md5)

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.clearToken)) { // 需要清空token的页面
    VueCookie.set('token', null);
    VueCookie.set('user', null);
  }
  if (to.matched.some(record => record.meta.requireAuth)){ // 判断该路由是否需要登录权限
	// next();
    const  token = VueCookie.get('token')
    if (token&&token!==''&&token!=='null') { // 判断当前的token是否存在 ； 登录存入的token
      console.log('有',token)
      next();
    } else {
      console.log('无token')
      next({
        path: '/login',
        query: {redirect: to.fullPath} // 将跳转的路由path作为参数，登录成功后跳转到该路由
      })
    }
  }
  else {
    next();
  }
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
